package command;

import machine.AgriculturalMachine;

public class MoveToCommand implements Command{
    private final AgriculturalMachine machine;
    private final String targetPosition;
    private String previousPosition;

    public MoveToCommand(AgriculturalMachine machine, String position) {
        this.machine = machine;
        this.targetPosition = position;
    }

    @Override
    public void execute() {
        System.out.println("执行命令: 移动 " + machine.getMachineId() + " 到 " + targetPosition);
        previousPosition = machine.getStatus().getPosition();
        machine.moveTo(targetPosition);
    }

    @Override
    public void undo() {
        System.out.println("撤销命令: 移动 " + machine.getMachineId() + " 回 " + previousPosition);
        machine.moveTo(previousPosition);
    }

    @Override
    public String getDescription() {
        return "移动 " + machine.getMachineId() + " 到 " + targetPosition;
    }
}
